<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            height: 3000px;
        }

        a {
            position: fixed;
            right: 0;
            bottom: 0;
        }
    </style>
</head>

<body>

    <a href="javascript:;">返回顶部</a>


    <script>

        var oA = document.querySelector('a');

        oA.onclick = function () {
            var t = setInterval(function () {
                document.documentElement.scrollTop -= 10;
                if(document.documentElement.scrollTop <= 0) {
                    clearInterval(t)
                }
            }, 1)
        }

    </script>

</body>

</html>